<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                fit: true,
                width: '100%',
                height: '100%',
                striped: true,
                pagination: true,
                url: "${contextPath}/security/hdw/exchange_order/page.htm?secondBatteryId=${(secondBatteryId)!}",
                fitColumns: true,
                pageSize: 10,
                pageList: [10, 50, 100],
                idField: 'id',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '订单编号',
                            align: 'center',
                            field: 'orderId',
                            width: 70,
                            formatter: function (val, row) {
                                return row.id;
                            }
                        },
                        {
                            title: '状态',
                            align: 'center',
                            field: 'orderStatusName',
                            width: 30
                        },
                        {
                            title: '充电柜/旧电池箱号/新电池箱号',
                            align: 'center',
                            field: 'cabinetId',
                            width: 80,
                            formatter: function (val, row) {
                                return row.cabinetId + '/' + row.firstBoxNum + '/' + row.secondBoxNum;
                            }
                        },
                        {
                            title: '客户手机',
                            align: 'center',
                            field: 'customerMobile',
                            width: 60
                        },
                        {
                            title: '金额(元)',
                            align: 'center',
                            field: 'price',
                            width: 30,
                            formatter: function (val, row) {
                                return new Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '下单时间',
                            align: 'center',
                            field: 'createTime',
                            width: 60
                        },
                        {
                            title: '付款时间',
                            align: 'center',
                            field: 'payTime',
                            width: 60
                        },
                        {
                            title: '付款类型',
                            align: 'center',
                            field: 'payTypeName',
                            width: 60
                        },
                        {
                            title: '操作',
                            align: 'center',
                            field: 'id',
                            width: 40,
                            formatter: function (val, row) {
                                var html = '<a href="javascript:view(\'ID\')">查看</a>';
                                html += ' <a href="javascript:view_map(\'ID\')">轨迹</a>';
                                <@app.has_oper oper_code='3_4_2'>
                                    if (row.orderStatus == 4) {
                                        html += ' <a href="javascript:divide(\'ID\')">金额分配</a>'
                                    }
                                </@app.has_oper>

                                if (row.orderStatus == 2||row.orderStatus == 3) {
                                    html += ' <a href="javascript:openFull(\'ID\')">分配满箱</a>'
                                }
                                return html.replace(/ID/g, row.id);
                            }
                        }
                    ]
                ],
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            })
        })

        function view_map(id) {
            $.post("${contextPath}/security/hdw/exchange_order_battery_report_log/find_all_map_count.htm", {orderId: id}, function (json) {
                if (!json.success) {
                    alert("该时段电池未上报信息");
                    return
                }
                App.dialog.show({
                    css: 'width:1286px;height:700px;overflow:visible;',
                    title: '运行轨迹',
                    href: "${contextPath}/security/hdw/exchange_order/view_map.htm?id=" + id
                });
            }, 'json');
        }
        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
        }

        function query() {
//            var tree = $('#suffix_tree');
//            var suffixId = tree.tree('getSelected');
//            if (suffixId) {
//                if (suffixId.id.length > 4) {
//                    suffixId = '_history_' + suffixId.id || '';
//                } else {
//                    suffixId = '';
//                }
//            } else {
//                suffixId = '';
//            }

            var agentId = $('input[name="agentId"]').val();
            var agencyId = $('input[name="agencyId"]').val();
            var customerMobile = $('#customer_mobile').val();
            var orderStatus = $('input[name="order_status"]').val();
            var datagrid = $('#page_table');
            var order_id = $('#order_id').val();
            datagrid.datagrid('options').queryParams = {
                agentId: agentId,
                agencyId: agencyId,
                orderStatus: orderStatus,
                customerMobile: customerMobile,
//                suffix: suffixId,
                id: order_id
            };
            datagrid.datagrid('load');
        }

        function openFull(id) {
            $.messager.confirm('提示信息', '将会为订单在对应终端打开一个满箱,非异常订单请谨慎操作?', function (ok) {
                if (ok) {
                    $.post("${contextPath}/security/hdw/exchange_order/open_full_box.htm?orderId=" + id, function (json) {
                        if (json.success == 1) {
                            $.messager.alert('提示消息', '操作成功', 'info');
                            reload();
                        } else {
                            $.messager.alert('提示消息', json.message, 'info');
                        }
                    }, 'json');
                }
            });
        }
        function view(id) {
//            var tree = $('#suffix_tree');
//            var suffixId = tree.tree('getSelected');
//            if (suffixId) {
//                if (suffixId.id.length > 4) {
//                    suffixId = '_history_' + suffixId.id || '';
//                } else {
//                    suffixId = '';
//                }
//            } else {
//                suffixId = '';
//            }
            App.dialog.show({
                css: 'width:776px;height:420px;',
                title: '查看',
                href: "${contextPath}/security/hdw/exchange_order/view.htm?id=" + id
            });
        }
        function divide(id) {
            App.dialog.show({
                css: 'width:776px;height:440px;',
                title: '金额分配',
                href: "${contextPath}/security/hdw/exchange_order_money_divide/divide.htm?orderId=" + id
            });
        }
        function balance(id) {
            $.post('${contextPath}/security/hdw/supplier/balance.htm', {
                id: id
            }, function (json) {
                <@app.json_jump/>
                $.messager.alert('提示信息', json.message, 'info');
                reload();
            }, 'json');
        }
    </script>
    </@app.head>
    <@app.body>
        <@app.container>
            <@app.banner/>

        <div class="main">
            <@app.menu/>

            <div class="content">
                <#--<div class="panel ztree_wrap" style="width: 110px">-->
                    <#--<div class="ztree" style="width: 110px">-->
                        <#--<div class="ztree_head">-->
                            <#--<h3>月份查询</h3>-->
                        <#--</div>-->
                        <#--<div class="ztree_body easyui-tree" id="suffix_tree"-->
                             <#--url="${contextPath}/security/hdw/exchange_order/monthTree.htm" lines="true"-->
                             <#--data-options="onBeforeSelect: App.tree.toggleSelect,-->
                                <#--onClick: function(node) {-->
                                    <#--query();-->
                                <#--}">-->
                        <#--</div>-->
                    <#--</div>-->
                <#--</div>-->
                <div class="panel search">
                    <div class="float_right">
                        <button class="btn btn_yellow" onclick="query()">搜索</button>
                    </div>
                    <table cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <td align="right">订单编号：</td>
                        <td><input type="text" class="text" id="order_id"/></td>
                        <td align="right">手机：</td>
                        <td><input type="text" class="text" id="customer_mobile"/></td>
                        <td align="right">状态：</td>
                        <td><select name="order_status" class="easyui-combobox" style="width: 142px; height: 28px;"
                                    editable="false">
                            <option value="">请选择</option>
                            <#list statusList as status>
                                <option value="${status.getValue()}">${status.getName()}</option>
                            </#list>
                        </select>
                        </td>
                        <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                            <td align="right">运营商：</td>
                            <td>
                                <input name="agentId" class="easyui-combotree" editable="false"
                                       style="width: 142px; height: 28px;"
                                       data-options="url:'${contextPath}/security/basic/agent/tree.htm?dummy=${'所有'?url}',method:'get',onSelect: function(rec){
                               var url = '${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId='+rec.id;
                               $('#agency_id').combotree('reload', url);},
                               onChange:function(){
                               $('#agency_id').combotree('clear');}"/>
                            </td>
                        </#if>
                        <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                            <td align="right">代理商：</td>
                            <td>
                                <input name="agencyId" class="easyui-combotree" editable="false" id="agency_id"
                                       data-options="url:'${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId=${Session['SESSION_KEY_USER'].agentId}'"
                                       style="width: 142px; height: 28px;"/>
                            </td>
                        </#if>
                    </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="toolbar clearfix">
                        <h3>换电订单</h3>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>
